package june.test_6_20;

import java.util.Map;
import java.util.Scanner;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] arr = new int[2001][2001];
        for (int i = 0; i < n; i++) {
            int xi = scanner.nextInt();
            int yi = scanner.nextInt();
            int ri = scanner.nextInt();
            int x1 = xi - ri + 1000;
            int x2 = xi + ri + 1000;
            int y1 = yi - ri + 1000;
            int y2 = yi + ri + 1000;
            setOne(arr,x1,x2,y1,y2);
        }
        int q = scanner.nextInt();
        for (int i = 0; i < q; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            System.out.println(arr[x + 1000][y + 1000]);
        }
    }
    private static void setOne(int[][] arr,int x1,int x2,int y1,int y2) {
        for (int i = x1; i <= x2; i++) {
            for (int j = y1; j <= y2; j++) {
                arr[i][j]++;
            }
        }
    }
}
